package com.yc.dao;

import java.util.Map;

/**
 *
 * @author UNO
 * 2021年6月25日下午8:56:26
 */
public class UserDao {
	/**
	 * 查找该用户的所有信息，用于登录，个人信息界面
	 * @param account
	 * @param pwd
	 * @return 返回一个map ，里面存储该用户的所有信息
	 */
	public Map<String, Object> findUserInfo(String account, String pwd){
		DBHelper db = new DBHelper();
		String sql = "select * from tb_user where u_name = ? and  u_pwd = ? ";
		return db.findSingle(sql, account, pwd);
	}
	
	//注册
	public int reg(byte[] photo, String account, String pwd, String cardid, String tel, String sex, String email){
		DBHelper db = new DBHelper();
		//insert into tb_user values(seq_user_id.nextval, null, 'navy', 'a', '430422199901111234', '17570893902', '男', '171333499@qq.com', default, 100);
		String sql = "insert into tb_user values(seq_user_id.nextval, ?, ?, ?, ?, ?, ?, ?, 0, 100)";
		return db.update(sql, photo, account, pwd, cardid, tel, sex, email);
	}
	//注销账号
	public int Cancel (String account) {
		DBHelper db = new DBHelper();
		String sql = "delete from tb_user where u_name = ? ";
		return db.update(sql, account);	
	}
	/**
	 * 修改个人信息
	 * @param photo
	 * @param account
	 * @param pwd
	 * @param tel
	 * @param email
	 * @param cardid
	 * @return
	 */
	public int upDateInfo(byte[] photo, String account, String pwd, String tel, String email, String cardid) {
		DBHelper db = new DBHelper();
		//update tb_user set u_name  = '王五', u_pwd = 'a', u_tel = '65498736584', u_email = '456798164@qq.com'
		//where u_cardid = '456789123456789852'
		String sql = "update tb_user set u_photo = ?, u_name  = ?, u_pwd = ? , u_tel = ?, u_email = ? where u_cardid = ?";		
		return db.update(sql, photo, account, pwd, tel, email, cardid);
	}

	/**
	 * 修改余额 ，用于 充值， 购票
	 * @param money
	 * @param account
	 * @return
	 */
	public int updateBalance(int money, String account) {
		DBHelper db = new DBHelper();
		//update tb_user set u_balance = (u_balance + 100) where u_name = '李四';
		String sql = "update tb_user set u_balance = (u_balance + ?) where u_name = ? ";
		return db.update(sql, money, account);
	}
}
